package com.sky.demo.singleton;

import java.io.IOException;
import java.util.Properties;

/**
 * Description:
 * 单例饿汉式方式三：静态代码块(适合复杂实例化)
 * 1、构造器私有化
 * 2、必须自行创建这个实例
 * 3、必须对外提供这个实例
 * @author Sky
 * @Date 2021/7/31 10:37
 */
public class HungrySingleton3 {

    // 外提供这个实例
    public static final HungrySingleton3 INSTANCE;

    private String info;

    // 构造器私有化
    private HungrySingleton3(String info){
        this.info = info;
    };

    static{

        try {

            Properties properties = new Properties();

            properties.load(HungrySingleton3.class.getClassLoader().getResourceAsStream("singleton.properties"));
            // 自行创建这个实例
            INSTANCE = new HungrySingleton3(properties.getProperty("info"));

        } catch (IOException e) {
            throw new RuntimeException();
        }

    }


    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    @Override
    public String toString() {
        return "HungrySingleton3{" +
                "info='" + info + '\'' +
                '}';
    }


}
